In [36]:
%matplotlib
import os
import ClearMap.IO as io
import ClearMap.Settings as settings
filename = os.path.join(settings.ClearMapPath, 'data/template_25.tif')


Using matplotlib backend: TkAgg

In [37]:
import ClearMap.Visualization.Plot as clrplt

In [38]:
# data = io.readData(filename);
# clrplt.plotTiling(data);
#'/root/plotter.py'

#import subprocess
#with open("/root/output.png", "w+") as output:
#    subprocess.call(["python", "/root/plotter.py"], stdout=output);

In [41]:
data = io.readData(filename);
#clrplt.plotTiling(data);
#clrplt.plotTiling(data, inverse = True);

In [43]:
#Tried to hack the code by manually editing the backend plot generation to save images. Didn't work'

# from PIL import Image

# img = Image.open('/root/output.png')
# img.show() */

Image Processing Suite


In [44]:
import ClearMap.ImageProcessing.BackgroundRemoval as bgr
dataBGR = bgr.removeBackground(data.astype('float'), size=(3,3), verbose = True);
#plt.plotTiling(dataBGR, inverse = True);


Background Removal: save: None
Background Removal: size: (3, 3)
Background: elapsed time: 0:00:02

In [45]:
from ClearMap.ImageProcessing.Filter.DoGFilter import filterDoG
dataDoG = filterDoG(dataBGR, size=(8,8,4), verbose = True);
#plt.plotTiling(dataDoG, inverse = True, z = (10,16));


DoG: save  : None
DoG: sigma2: None
DoG: sigma : None
DoG: size  : (8, 8, 4)
DoG: elapsed time: 0:00:30

In [46]:
from ClearMap.ImageProcessing.MaximaDetection import findExtendedMaxima
dataMax = findExtendedMaxima(dataDoG, hMax = None, verbose = True, threshold = 10);
#plt.plotOverlayLabel( dataDoG / dataDoG.max(), dataMax.astype('int'))


Extended Max: threshold: 10
Extended Max: save     : None
Extended Max: hMax     : None
Extended Max: size     : 5
Extended Max: elapsed time: 0:00:03

In [47]:
from ClearMap.ImageProcessing.MaximaDetection import findCenterOfMaxima
cells = findCenterOfMaxima(data, dataMax);
print cells.shape


(26, 3)

In [ ]:
#plt.plotOverlayPoints(data, cells)

Cell Shape Detection


In [48]:
from ClearMap.ImageProcessing.CellSizeDetection import detectCellShape
dataShape = detectCellShape(dataDoG, cells, threshold = 15);
#plt.plotOverlayLabel(dataDoG / dataDoG.max(), dataShape, z = (10,16))


/usr/local/lib/python2.7/dist-packages/ClearMap-0.9.2-py2.7-linux-x86_64.egg/ClearMap/Analysis/Voxelization.py:90: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  vox[points[i,0], points[i,1], points[i,2]] += weights[i];

In [49]:
from ClearMap.ImageProcessing.CellSizeDetection import findCellSize, findCellIntensity
cellSizes = findCellSize(dataShape, maxLabel = cells.shape[0]);
cellIntensities = findCellIntensity(dataBGR, dataShape, maxLabel = cells.shape[0]);

In [51]:
%pyplot
import matplotlib.pyplot as mpl
mpl.figure()
mpl.plot(cellSizes, cellIntensities, '.')
mpl.xlabel('cell size [voxel]')
mpl.ylabel('cell intensity [au]')


ERROR:root:Line magic function `%pyplot` not found.
---------------------------------------------------------------------------
TclError                                  Traceback (most recent call last)
<ipython-input-51-78e136071535> in <module>()
      1 get_ipython().magic(u'pyplot')
      2 import matplotlib.pyplot as mpl
----> 3 mpl.figure()
      4 mpl.plot(cellSizes, cellIntensities, '.')
      5 mpl.xlabel('cell size [voxel]')

/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
    525                                         frameon=frameon,
    526                                         FigureClass=FigureClass,
--> 527                                         **kwargs)
    528 
    529         if figLabel:

/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
     82     FigureClass = kwargs.pop('FigureClass', Figure)
     83     figure = FigureClass(*args, **kwargs)
---> 84     return new_figure_manager_given_figure(num, figure)
     85 
     86 

/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
     90     """
     91     _focus = windowing.FocusManager()
---> 92     window = Tk.Tk()
     93     window.withdraw()
     94 

/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
   1816                 baseName = baseName + ext
   1817         interactive = 0
-> 1818         self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
   1819         if useTk:
   1820             self._loadtk()

TclError: no display name and no $DISPLAY environment variable

In [ ]: